//
//  XDWithdrawProgressViewController.m
//  xindailianmeng
//
//  Created by 张东 on 2017/2/14.
//  Copyright © 2017年 xindailianmeng.cn. All rights reserved.
//

#import "XDWithdrawProgressViewController.h"
#import "AFHTTPSessionManager+POST.h"
#import "XDWithdrawProgressModel.h"
#import "MJExtension.h"
#import "XDWithdrawProgressView.h"
#import "XDWithdrawProgressCell.h"
#import "ZHRTBasicMethod.h"
@interface XDWithdrawProgressViewController ()<UITableViewDelegate, UITableViewDataSource, XDWithdrawProgressCellDelegate>
@property (nonatomic, strong) XDWithdrawProgressModel *model;

@property (nonatomic, weak) UITableView *tableView;

@property (nonatomic, weak) XDWithdrawProgressView *withdrawView;

@property (nonatomic, strong) NSArray *withdrawArr;
@end

@implementation XDWithdrawProgressViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor  = [UIColor whiteColor];
    self.title = @"提现进度";
    
    [self setupUI];
    [self loadData];
}
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
    // 禁用 iOS7 返回手势
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    }
}

- (void)loadData {
    
    NSDictionary * param = @{@"method":@"getWithdrawalsIng",@"wdId":[NSString stringWithFormat:@"%zd",self.wdId]};
    [AFHTTPSessionManager POSTWithParams:param success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if ([responseObject[@"code"] isEqualToString:@"100000"]) {
            
            /*
             
             code = 100000;
             message = "\U64cd\U4f5c\U6210\U529f";
             result =     {
             bankName = "<null>";
             ctime = "2017-02-09 15:43:49";
             endTime = "2017-02-15 09:15:25";
             ingTime = "2017-02-09 15:53:49";
             money = 100;
             startTime = "2017-02-09 15:43:49";
             type = "\U63d0\U73b0";
             wdId = 57;
             wdStatus = 4;
             wdStatusMsg = "\U4ea4\U6613\U6210\U529f";
             };
             type = success;
             */
            self.model = [XDWithdrawProgressModel mj_objectWithKeyValues:responseObject[@"result"]];
            self.withdrawView.model = self.model;
          
            _withdrawArr = @[
                             @[@"交易类型",self.model.type],
                             @[@"交易时间",self.model.ctime],
                             @[@"提现金额",  [NSString stringWithFormat:@"%@元",[ZHRTBasicMethod ChangeNumberFormat:[NSString stringWithFormat:@"%.2f",self.model.money]]]],
                             @[@"交易状态",self.model.wdStatusMsg],
                             
                             ];
            [self.tableView reloadData];
            
            
        } else if ([responseObject[@"code"] isEqualToString:@"100001"]){ // 超时
            
            
        } else {
            
            
        }
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
    
}
- (void)setupUI {
    
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH - 64) style:UITableViewStyleGrouped];
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.showsVerticalScrollIndicator = NO;
    tableView.showsHorizontalScrollIndicator = NO;
    [self.view addSubview:tableView];
    self.tableView = tableView;
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, 30)];
    tableView.tableFooterView = view;
    
    XDWithdrawProgressView *withdrawView = [[NSBundle mainBundle] loadNibNamed:@"XDWithDrawProView" owner:self options:nil].firstObject;
    self.withdrawView = withdrawView;
    tableView.tableHeaderView = withdrawView;
    
}

#pragma mark -- table
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *myID = @"XDBackMoneyTableViewCell";
    XDWithdrawProgressCell *cell = [tableView dequeueReusableCellWithIdentifier:myID];
    if (cell == nil) {
        cell = [[XDWithdrawProgressCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:myID];
    }
    [cell withdrawProgressCellWithTitle:self.withdrawArr[indexPath.row][0] details:self.withdrawArr[indexPath.row][1]];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.delegate = self;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.001;
}

- (void)withdrawProgressCellTipBtnClick:(XDWithdrawProgressCell *)cell {
    
    NSLog(@"提现失败原因");
    
    
    
}

@end
